#include "MatrixIntParam.h"

MatrixIntParam::MatrixIntParam()
:Param() { 
	values = NULL;
	size = 0;
	label = 0;
}

MatrixIntParam::MatrixIntParam( int row, char rowLabel, const char *name )
:Param( name ) {
	this->size = row;
	this->label = rowLabel;
	this->values = new ArrayIntParam[row];
	this->ready = true;
}

MatrixIntParam::MatrixIntParam( int row, int col, char rowLabel, char colLabel, const char *name )
:Param( name ) {
	this->size = row;
	this->label = rowLabel;
	this->values = new ArrayIntParam[row];
	for (int i = 0; i < row; i++)
		values[i] = ArrayIntParam(col, colLabel, name);

	this->ready = true;
}

MatrixIntParam::MatrixIntParam( MatrixIntParam &src )
:Param( src ) {
	this->size = src.size;
	this->label = src.label;
	this->values = Util::copyArray<ArrayIntParam> (src.values, size);
	this->ready = src.ready;
}

MatrixIntParam::~MatrixIntParam() {
	delete [] values;
}

void MatrixIntParam::read( Input &input ) throw (NotReady) {
	if (!ready) throwNotReady();
	for (int i = 0; i < size; i++)
		values[i].read(input);
}

ArrayIntParam &MatrixIntParam::get( int i ) throw (InvalidIndex, NotReady) {
	if (!ready) throwNotReady();
	if (i < 0 || i >= size)
		throw new InvalidIndex( &label, 0, size-1, i );

	return values[i];
}

ArrayIntParam &MatrixIntParam::operator [] ( int i ) throw (InvalidIndex, NotReady) {
	return get(i);
}

void MatrixIntParam::setSize( int size ) throw (NotReady) {
	if (!ready) throwNotReady();

	ArrayIntParam *sub = new ArrayIntParam[size];
	for (int i = 0; i < size && i < this->size; i++)
		sub[i] = values[i];

	delete [] values;
	this->values = sub;
	this->size = size;
}

void MatrixIntParam::setLabel( char label ) throw (NotReady) {
	if (!ready) throwNotReady();

	this->label = label;
}

int MatrixIntParam::getSize() throw (NotReady) {
	if (!ready) throwNotReady();

	return size;
}

char MatrixIntParam::getLabel() throw (NotReady) {
	if (!ready) throwNotReady();

	return label;
}